#include "MainWindow.h"

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    // 创建数据库连接
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("paths.db");

    if (!db.open()) {
        qDebug() << "Error: connection with database failed";
        return -1;
    }

    // 创建表
    QSqlQuery query;
    query.exec("CREATE TABLE IF NOT EXISTS paths ("
               "id INTEGER PRIMARY KEY AUTOINCREMENT, "
               "path TEXT, "
               "description TEXT)");

    // 插入数据
    query.prepare("INSERT INTO paths (path, description) VALUES (:path, :description)");
    query.bindValue(":path", "C:/Program Files");
    query.bindValue(":description", "Main program directory");
    query.exec();

    // 查询数据
    query.exec("SELECT * FROM paths");
    while (query.next()) {
        QString path = query.value(1).toString();
        QString description = query.value(2).toString();
        qDebug() << "Path:" << path << "Description:" << description;
    }

    db.close();

    return app.exec();
}
